package com.douwong.student.activity;

import android.view.View;
import android.widget.TextView;

import com.douwong.student.R;
import com.douwong.student.application.BaseApplication;
import com.douwong.student.base.BaseActivity;
import com.douwong.student.factory.ThreadFactory;
import com.douwong.student.socket.TCPReconnect;
import com.douwong.student.utils.NetUtils;
import com.douwong.student.utils.ToastUtils;

/**
 * @autor yichao
 * @time 2017/4/116:02
 * @des 断线重连失败显示界面
 */
public class ReconnectActivity extends BaseActivity {
    public static boolean isShown;
    private TextView mTvSure,mTvCancel;


    @Override
    protected void initView() {
        setContentView(R.layout.activity_reconnect);
        mTvSure = (TextView) findViewById(R.id.update_text);
        mTvCancel = (TextView) findViewById(R.id.not_update_text);

    }

    @Override
    protected void initEvent() {
        super.initEvent();
        mTvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //重新加入课堂
                if (NetUtils.isWIFINetWork(ReconnectActivity.this)){
                    if (!BaseApplication.isLoginClass){
                        ThreadFactory.getNormalPool().execute(new Runnable() {
                            @Override
                            public void run() {
                                TCPReconnect.reconnectCount=0;
                                TCPReconnect.getInstance().reconnectTcp(ReconnectActivity.this);
                                finish();
                            }
                        });

                    }

                }else {
                    ToastUtils.makeText(ReconnectActivity.this,"网络未连接");
                }




            }
        });
        mTvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //取消
                finish();


            }
        });

    }

    @Override
    protected void initData() {
        super.initData();
        isShown=true;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        isShown=false;
        TCPReconnect.reconnectCount=0;
    }
}
